package com.xintonghua.bussiness.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xintonghua.base.adapter.BaseAdapter;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.bean.ProductBean;
import com.xintonghua.bussiness.util.GlideUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：wanxianyi
 * 时间：2018/1/13.
 * 包名：com.xintonghua.hongyi.adapter
 */

public class ProductAdapter extends BaseAdapter<ProductBean.ListBean, ProductAdapter.ProductViewHolder> {


    public ProductAdapter(Activity mActivity, List<ProductBean.ListBean> list) {
        super(mActivity, list);
    }

    @Override
    public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.adapter_product, parent, false);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


            }
        });
        return new ProductViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ProductViewHolder holder, int position) {


        ProductBean.ListBean bean = getList().get(position);
        GlideUtils.load(mActivity, holder.ivProduct, bean.getLogo());
        holder.tvProductCount.setText("剩余" + bean.getNumber() + "瓶");
        holder.tvProductNumber.setText("" + bean.getSpecifications()+"/"+bean.getUnit());
        holder.tvProductPrice.setText("¥"+bean.getPrice());
        holder.tvProductName.setText(""+bean.getName());

    }

    class ProductViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_product)
        ImageView ivProduct;
        @BindView(R.id.tv_product_name)
        TextView tvProductName;
        @BindView(R.id.tv_product_number)
        TextView tvProductNumber;
        @BindView(R.id.tv_product_price)
        TextView tvProductPrice;
        @BindView(R.id.tv_product_count)
        TextView tvProductCount;

        public ProductViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
